<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑员工 - 员工信息管理系统</title>
    <style>
        .container { width: 800px; margin: 50px auto; padding: 20px; box-shadow: 0 0 10px #eee; }
        .form-group { margin-bottom: 15px; }
        label { display: inline-block; width: 100px; text-align: right; margin-right: 10px; }
        input, select { padding: 6px; width: 300px; box-sizing: border-box; }
        .btn { padding: 8px 20px; background: #2196F3; color: white; border: none; cursor: pointer; }
        .error { color: red; margin-left: 110px; font-size: 12px; }
        .message { color: green; text-align: center; margin-bottom: 20px; }
    </style>
</head>
<body>
<div class="container">
    <h2>编辑员工</h2>

    <!-- 操作结果提示 -->
    <div class="message" th:if="${message != null}" th:text="${message}"></div>
    <div class="error" th:if="${error != null}" th:text="${error}"></div>

    <form action="/employee/edit" method="post" th:object="${employee}">
        <!-- 隐藏ID（用于更新） -->
        <input type="hidden" name="id" th:field="*{id}">

        <!-- 姓名 -->
        <div class="form-group">
            <label for="name">姓名：</label>
            <input type="text" id="name" name="name" required
                   th:field="*{name}">
            <p class="error" th:if="${#fields.hasErrors('name')}"
               th:errors="*{name}">姓名不能为空</p>
        </div>

        <!-- 部门 -->
        <div class="form-group">
            <label for="department">部门：</label>
            <input type="text" id="department" name="department" required
                   th:field="*{department}">
            <p class="error" th:if="${#fields.hasErrors('department')}"
               th:errors="*{department}">部门不能为空</p>
        </div>

        <!-- 职位 -->
        <div class="form-group">
            <label for="position">职位：</label>
            <input type="text" id="position" name="position" required
                   th:field="*{position}">
            <p class="error" th:if="${#fields.hasErrors('position')}"
               th:errors="*{position}">职位不能为空</p>
        </div>

        <!-- 薪资 -->
        <div class="form-group">
            <label for="salary">薪资：</label>
            <input type="number" step="0.01" min="0" id="salary" name="salary" required
                   th:field="*{salary}">
            <p class="error" th:if="${#fields.hasErrors('salary')}"
               th:errors="*{salary}">薪资不能为空且必须为正数</p>
        </div>

        <!-- 邮箱 -->
        <div class="form-group">
            <label for="email">邮箱：</label>
            <input type="email" id="email" name="email"
                   th:field="*{email}">
        </div>

        <!-- 电话 -->
        <div class="form-group">
            <label for="phone">电话：</label>
            <input type="text" id="phone" name="phone"
                   th:field="*{phone}">
        </div>

        <!-- 入职日期 -->
        <div class="form-group">
            <label for="hireDate">入职日期：</label>
            <input type="date" id="hireDate" name="hireDate" required
                   th:field="*{hireDate}">
            <p class="error" th:if="${#fields.hasErrors('hireDate')}"
               th:errors="*{hireDate}">入职日期不能为空</p>
        </div>

        <!-- 提交按钮 -->
        <div class="form-group">
            <label></label>
            <button type="submit" class="btn">更新</button>
            <button type="button" class="btn" style="background: #f44336; margin-left: 10px;"
                    onclick="window.location.href='/employee'">取消</button>
        </div>
    </form>
</div>
</body>
</html>